home *** CD-ROM | disk | FTP | other *** search
Wrap
DefInt A-Z 'Declaration for checking disk's free space. DLL which comes with VBINST. 'Turbo Pascal for Windows source code included. Declare Function DFree Lib "vbinst.dll" (ByVal Disk As Integer) As Long '------------------------------------------- 'API Declarations for reading install.inf 'and detecting windows and system directory. '------------------------------------------- Declare Function GetWindowsDirectory Lib "Kernel" (ByVal WD As String, ByVal nWSize As Integer) As Integer Declare Function GetSystemDirectory Lib "Kernel" (ByVal WSD As String, ByVal nSSize As Integer) As Integer Declare Function GetPrivateProfileString Lib "Kernel" (ByVal lpApplication As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal FileStr As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer Global Const IDYES = 6 'define msgbox return value Global SD As String 'source dir Global WD As String 'windows dir (see form load procedure) Global WSD As String 'windows system dir (see form load procedure) Global WarnFlag As Integer 'flag to overwrite warning '--------------------------------- 'variables for checking diskspace. '--------------------------------- Global LoadDir As String 'form load default dest dir Global DestDrive As String 'chosen drive to check free diskspace '---------------------------------------------------- 'variables for reading private ini file (install.inf) '---------------------------------------------------- Global nSize As Integer Global lpFileName As String 'must use fixed-lenght variable because DLL's return Global FileStr As String * 256 'Type for LZCopy Type OFSTRUCT cBytes As String * 1 fFixedDisk As String * 1 nErrCode As Integer reserved As String * 4 szPathName As String * 128 End Type 'API calls and constants for LZCopy Declare Function LZOpenFile Lib "LZexpand.dll" (ByVal lpszFile$, lpOf As OFSTRUCT, ByVal style%) As Integer Declare Function LZCopy Lib "LZexpand.dll" (ByVal hfSource%, ByVal hfDest%) As Long Declare Sub LZClose Lib "LZexpand.dll" (ByVal hfFile%) Global Const OF_CREATE = &H1000 Global Const OF_READ = &H0 Global Const OF_DELETE = &H200 '------------------------------------------- 'variables for IniCopy and LZCopy. '------------------------------------------- Global Source As String 'source file Global Dest As String 'destination file Global DestDir As String 'destination dir for program files Function GetSource (Arg1 As String) As String X% = InStr(Arg1$, ",") GetSource$ = Left$(Arg1$, X% - 1) End Function Sub IniCopy (lpApplication As String, lpKeyName As String, lpDefault As String, SubDir As String) '----------------------------------------------------------------- 'This routine reads files from install.inf to be copied system 'and program directory. 'WhichDisk% and Disk% are two variables to determine correct 'disks from which to copy files. Each installation disk must have 'ID file representing that disk in istallation procedure. 'For example first installation disk must has file named 1, second 'disk must has file named 2 and so on. There is no matter what ID 'file contains, it it just identifier to installation program to 'look for correct disk at time. '----------------------------------------------------------------- Dim WhichDisk%, Disk% Dim Match$ WhichDisk% = 1 '----------------------------------------------------------------- 'Next loop reads information from install.inf; files to be copied, 'and prompt for correct installtion disk's '----------------------------------------------------------------- I = 0 Do I = I + 1 Screen.MousePointer = 11 'hourglass State% = DoEvents() 'allows list files to copied to be updated lpKeyName$ = "file" + Str$(I) GetStringvar% = GetPrivateProfileString(lpApplication$, lpKeyName$, lpDefault$, FileStr$, nSize%, lpFileName$) '---------------------------- 'Check named mark to end loop '---------------------------- If Left$(FileStr$, 7) = "EndMark" Then Exit Do ElseIf Left$(FileStr$, 8) = "EndMark" Then Exit Do End If '------------------------------------------------------- 'Get installation disk number after file's name it 'reads from install.inf. For example file 5=myprog.exe,2 'where myprog.exe represents file to be istalled and 'after comma (,) 2 represents installation disk number 'from where to look for file. '------------------------------------------------------- Disk% = Val(Right$(Left$(FileStr$, GetStringvar%), 1)) If Disk% > WhichDisk% Then WhichDisk% = Disk% '------------------------------------------------------ 'If installation program has reach last file from disk, 'prompt user to change new disk to source drive and do 'correct error checking. '------------------------------------------------------ WrongDisk: MsgBox "Insert disk number " + Str$(Disk%), 64, "Another disk required!" '--------------------------------------------------- 'Look for disk ID file to dtermine correct disk and 'get rid off leading blanks that Str$ function adds. 'If user press enter and disk is not ready, let them 'know and try again. SD$ is source drive. '--------------------------------------------------- On Error Resume Next Match$ = Dir$(RTrim$(LTrim$(Str$(WhichDisk%)))) If Err = 71 Then MsgBox "There is no disk in drive " + Left$(SD$, 2), 48, "Device error" Err = 0 GoTo WrongDisk End If If Match$ = "" Then GoTo WrongDisk Install.Refresh End If 'copy all program files to destination dir File$ = RTrim$(Left$(FileStr$, GetStringvar% - 2)) 'move spaces and disk ID from right Source$ = SD$ + GetSource$(File$) 'Get source file's name Dest$ = SubDir$ + "\" + Mid$(File$, Len(GetSource$(File$)) + 2) 'Get destination file's name '--------------------------------------------------------------- 'Check if file already exist. If so, load Warn form and let user 'determine overwriting. WarnFlag is boolean to determine, if 'user has chosen overwrite all files, so installation does not 'prompt overwriting warning anymore. '--------------------------------------------------------------- IsFile$ = Dir$(Dest$) If IsFile$ = "" Then Install.Lbl_List.Caption = "Now copying file " + File$ + " from disk" + Str$(WhichDisk%) LZFileCopy Source$, Dest$ Install.List1.AddItem Dest$ Else Screen.MousePointer = 0 If WarnFlag = True Then Warn.Lbl_Warn.Caption = "File already exist!, would you like to overwrite it? " + Dest$ 'give the user a change to prevent overwriting Warn.Show 1 Else Install.Lbl_List.Caption = "Now copying file " + File$ + " from disk" + Str$(WhichDisk%) LZFileCopy Source$, Dest$ Install.List1.AddItem Dest$ End If End If Loop Screen.MousePointer = 0 'default mousepointer End Sub Sub IniGrpItem (lpApplication As String, lpKeyName As String, lpDefault As String) 'start loop I = 0 Do I = I + 1 lpKeyName$ = "file" + Str$(I) GetStringvar% = GetPrivateProfileString(lpApplication$, lpKeyName$, lpDefault$, FileStr$, nSize%, lpFileName$) 'Get items command line and after "," in install.inf item's title DestFile$ = DestDir$ + "\" + RTrim$(Left$(FileStr$, GetStringvar%)) 'get the item's title DestTitle$ = Mid$(DestFile$, (InStr(DestFile$, ",")) + 1, InStr(DestFile$, ";") - InStr(DestFile$, ",") - 1) 'if you omit the item's title put title from file's name If DestTitle$ = "" Then DestTitle$ = Mid$(FileStr$, 1, (InStr(FileStr$, ",")) - 1) End If 'get the item's icon ItemIcon$ = Mid$(DestFile$, (InStr(DestFile$, ";")) + 1) 'if you omit the item's icon use default icon If Not ItemIcon$ = "" Then ItemIcon$ = DestDir$ + "\" + ItemIcon$ End If 'get the item's command line DestFile$ = Left$(DestFile$, (InStr(DestFile$, ",")) - 1) 'check named mark to end loop If Left$(FileStr$, 7) = "EndMark" Then Exit Do ElseIf Left$(FileStr$, 8) = "EndMark" Then Exit Do End If For X% = 1 To 10 'Give time for DDE response z% = DoEvents() Next Install.Lbl_List.LinkExecute "[AddItem(" + DestFile$ + "," + DestTitle$ + "," + ItemIcon$ + ")]" Loop 'Install.Lbl_List.LinkTimeout = 50 Install.Lbl_List.LinkMode = 0 End Sub Sub LZFileCopy (Source$, Dest$) '--------------------------------------------------------- 'This procedure shows how easily you can use LZexpand.dll 'WIN 3.1 API function to copy file. It also decompress the 'file if the file is in compressed mode (if the file was 'compressed using compress.exe in SDK 3.1). You can remove 'Print and DoEvents() lines because they only show what 'is currently happening. '--------------------------------------------------------- '------------------------ 'Declare file structures. '------------------------ Dim lpSrc As OFSTRUCT Dim lpDst As OFSTRUCT '--------------------- 'Open the source file. '--------------------- SrcFile% = LZOpenFile(Source$, lpSrc, OF_READ) '---------------------------- 'Create the destination file. '---------------------------- DstFile% = LZOpenFile(Dest$, lpDst, OF_CREATE) '--------------------------------------------- 'Copy the source file to the destination file. '--------------------------------------------- DoCopy& = LZCopy(SrcFile%, DstFile%) '---------------- 'Close the files. '---------------- LZClose SrcFile% LZClose DstFile% End Sub